#ifndef HEADER_A7B3C0613EE6D478
#define HEADER_A7B3C0613EE6D478

/* uuid32.h
   2007-09-15 Last created by cheungmine.
   Partly rights reserved by cheungmine.
*/
#ifndef MIDGARD_UUID_H
#define MIDGARD_UUID_H

#include <stdlib.h>
#include <assert.h>
#include <string.h>
#include <memory.h>

#ifndef BOOL
	typedef int BOOL;
	#define TRUE  1
	#define FALSE 0
#endif

typedef unsigned char uchar;
typedef unsigned  short uint16, word_t;
typedef unsigned  int uint32, dword_t;
typedef long long int64;

typedef struct _uuid_t
{
	dword_t	data1;
	word_t	data2;
	word_t	data3;
	uchar	data4[8];
} UUID_t;

/**
 * Checks whether the given string matches the UUID format.
 *	params:
 *     [in] uuid - uuid the potential UUID string
 *	return
 *     TRUE if the given string is a UUID, FALSE otherwise
 **/
BOOL is_uuid_string(const char *uuid);

/**
 * Generates a new UUID. The UUID is a time-based time 1 UUID.
 * A random per-process node identifier is used to avoid keeping global
 * state and maintaining inter-process synchronization.
 **/
extern void uuid_create(UUID_t* uuid);

/**
 * Generates a new UUID string. The returned UUID is a time-based time 1 UUID.
 * A random per-process node identifier is used to avoid keeping global
 * state and maintaining inter-process synchronization.
 *  return UUID string (newly allocated)
 **/
char *uuid_create_string(void);

/**
 * Generates a name-based (type 3) UUID string from the given external
 * identifier. The special namespace UUID is used as the namespace of
 * the generated UUID.
 *  params
 *     [in] external - the external identifier
 *  return
 *     UUID string (newly allocated)
 **/
void uuid_create_external(const char *external, UUID_t* uuid);

/**
 * Translate a uuid_t to a uuid string
 *  return UUID string
 **/
char *uuid_to_string(const UUID_t* uuid);

#endif

#endif // header guard
